package br.ufla.pgcc.oomeasures.measures;

import br.ufla.pgcc.oomeasures.astvisitors.ClassVisitor;
import br.ufla.pgcc.oomeasures.astvisitors.MethodVisitor;

/**
 * Classe que implementa a medida da suite MOOD Method Hiding Factor, que mede as invisibilidades de metodos em classes. 
 * A invisibilidade de um metodo eh a percentagem do total de classes de que o metodo nao e visivel.
 * 
 * @author Ramon Abilio
 *
 */
public class MethodHidingFactor extends Measure{

	private double value;
	
	public MethodHidingFactor(){
		super();
		value=0d;
		addApplicableGranularity(Granularity.CLASS);
	}
	
	@Override
	public String getName() {
		return "Method hiding factor";
	}

	@Override
	public String getAcronym() {
		return "MHF";
	}

	@Override
	public String getDescription() {
		return "Measures how the methods are encapsulated in a class";
	}

	@Override
	public double getMinValue() {
		return 0;
	}

	@Override
	public double getMaxValue() {
		return 1;
	}

	@Override
	public double getRefValue() {
		return 1;
	}

	@Override
	public double getCalculatedValue() {
		return value;
	}

	@Override
	public void setCalculatedValue(double value) {
		this.value = value;
	}

	@Override
	public <T> void measure(T unit) {

		double numOfPrivateMethods = MethodVisitor.getNumberOfProjectPrivateMethods();
		double numOfClasses        = ClassVisitor.getNumOfProjectClasses();
		double numOfMethods        = MethodVisitor.getNumberOfProjectMethods();
		
		double mhf = 100 - ((numOfPrivateMethods/(numOfClasses-1)/numOfMethods)*100);
		setCalculatedValue(mhf);

	}
}
